import {
  Body,
  Controller,
  Get,
  Post,
  HttpCode,
  HttpStatus,
  Param
} from '@nestjs/common';
import { Report } from '@/entity/report/report.entiy';
import { ReportService } from './report.service';

@Controller('/api/report')
export class ReportController {
  constructor(private readonly ReportService: ReportService) {}

  @HttpCode(HttpStatus.OK)
  @Post('complaint')
  async complaint(@Body() postParams: any): Promise<any> {
    try {
      const res = await this.ReportService.insertData({
        ...postParams,
        reportTime: new Date(),
      });
      console.log('举报', res);
      if (res) {
        return {
          code: 200,
          data: res,
          message: 'ok',
        };
      } else {
        return {
          code: 1000,
          data: null,
          message: '接口提交失败',
        };
      }
    } catch (error) {
      return {
        code: 500,
        message: error,
      };
    }
  }


  @HttpCode(HttpStatus.OK)
  @Get('findReportByUserId/:userId')
  async findReportByUserId(
    @Param('userId') userId: string,
  ): Promise<{ code: number; data: Array<Report>; message: string }> {
    try {
      const reportData = await this.ReportService.findReportByUserId(userId);
      console.log('reportData', reportData);
      if (reportData) {
        return {
          code: 200,
          data: reportData,
          message: 'ok',
        };
      } else {
        return {
          code: 1000,
          data: null,
          message: 'error',
        };
      }
    } catch (error) {
      return {
        code: 500,
        data: null,
        message: error,
      };
    }
  }
}
